﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{




    /// <summary>
    /// 测试一个返回string 的Controller
    /// </summary>
    public class TestController : Controller
    {
        //GET: Test
        public ActionResult GetString()
        {
            return View("实验5强类型");
        }

        /// <summary>
        /// 定义一个返回对象的Action
        /// </summary>
        /// <returns></returns>
        public Customer GetCustomer()
        {
            Customer c = new Customer();
            c.CustomerName = "姓名";
            c.Address = "地址";
            return c;
        }

        /// <summary>
        /// 创建一个非Action的方法。
        /// </summary>
        /// <returns></returns>
        [NonAction]
        public string DemoMethod()
        {
            return "这不是一个Action";
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult GetView()
        {
            Random r = new Random();
            Employee emp = new Employee();
            emp.FirstName = "Sukesh";
            emp.LastName = "Marla";
            emp.Salary = 20000;
            ViewBag.Employee = emp;
            if (r.Next() % 2 == 1)
            {
                return View("MyView");
            }
            else
            {
                return View("YouView");
            }
        }


}





    /// <summary>
    /// 定义一个对象
    /// </summary>
    public class Customer
    {
        public string CustomerName { get; set; }
        public string Address { get; set; }


        public override string ToString()
        {
            return this.CustomerName + "|" + this.Address;
        }
    }



}